<template>
  <div class="goods-hot" v-if="goodsList.length>0">
    <h3>{{TYPES[type]}}</h3>
    <!-- 商品区块 -->
    <RouterLink :to="`/goods/${item.id}`" class="goods-item" v-for="item in goodsList" :key="item.id">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis">{{item.name}}</p>
      <p class="desc ellipsis">{{item.desc}}</p>
      <p class="price">&yen;{{item.price}}</p>
    </RouterLink>
  </div>
</template>
<script>
import { findHotGoods } from '@/api/goods'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
// 一对一 并且好扩展 枚举
const TYPES = {
  1: '24小时热榜',
  2: '周热榜',
  3: '总热销榜'
}
export default {
  name: 'GoodsHot',
  props: {
    type: {
      type: Number
    }
  },
  setup (props) {
    // 商品列表
    const route = useRoute()
    const goodsList = ref([])
    async function getData () {
      const { data: { result } } = await findHotGoods({ id: route.params.id, type: props.type })
      goodsList.value = result
    }
    getData()
    return { goodsList, TYPES }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
